package com.hdu.xxl_job_client.res.job;


import lombok.Data;

import java.util.List;

import static java.util.Objects.nonNull;

@Data
public class XxlJobExecuteRes {

    private static final Integer SUCCESS_CODE = 200;
    private static final Integer FAIL_CODE = 500;

    private Integer code;
    private String msg;
    private String content;
    private Integer recordsFiltered;
    private Integer recordsTotal;
    private List<XxlJobInfoRes> data;

    public boolean isSuccess() {
        return SUCCESS_CODE.equals(code) ||
                (nonNull(recordsTotal) && recordsTotal > 0);
    }

    public boolean isFail() {
        return FAIL_CODE.equals(code);
    }

    public static XxlJobExecuteRes success() {
        XxlJobExecuteRes xxlJobExecuteRes = new XxlJobExecuteRes();
        xxlJobExecuteRes.setCode(SUCCESS_CODE);
        return xxlJobExecuteRes;
    }

    public static XxlJobExecuteRes fail(String msg) {
        XxlJobExecuteRes xxlJobExecuteRes = new XxlJobExecuteRes();
        xxlJobExecuteRes.setCode(FAIL_CODE);
        xxlJobExecuteRes.setMsg(msg);
        return xxlJobExecuteRes;
    }

    public void setJobId(String jodId) {
        this.content = jodId;
    }

    public String getJobId() {
        return content;
    }
}
